<?php
/**
 * User: Hufeng
 * Date: 2015/12/15 17:36
 * Desc: 核心文件
 */
namespace SasPHP;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

class SasTimer{

    static public function start($c,$v) {
        // 注册AUTOLOAD方法
        spl_autoload_register('SasPHP\SasTimer::autoload');
        register_shutdown_function('SasPHP\SasTimer::handleFatal');
        return self::dispatch($c,$v);
    }

    // 异常处理
    static public function handleFatal(){
        $errorMsg = error_get_last();
        $log = new Logger('yltsas');
        $date = date('Ymd');
        $log->pushHandler(new StreamHandler('/var/www/staticRes/Runtime/'.$date.'.log', Logger::WARNING));
        $log->error($errorMsg['message']."====>\n".$errorMsg['file']."=====>\n".$errorMsg['line']);
    }

    static public function autoload($class) {
        require_once BASEDIR.'/'.str_replace('\\', '/', $class).'.php';
    }

    static public function dispatch($c,$v){
        return self::exec($c,$v);
    }

    static public function exec($c,$v){
        $class = '\\App\\Controller\\'.$c;
        $obj = new $class();
        return $obj->$v();
    }
}

